package org.example;
// 第一个类：学生类
class Student {
    // 属性
    private String name;
    private int age;
    private String gender;
    private String studentId;
    private double gpa;

    // 构造方法
    public Student(String name, int age, String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.studentId = generateStudentId();
        this.gpa = 0.0;
    }

    public Student(String name, int age, String gender, double gpa) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.studentId = generateStudentId();
        this.gpa = gpa;
    }

    public Student(String name, int age, String gender, String studentId, double gpa) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.studentId = studentId;
        this.gpa = gpa;
    }

    // 方法
    public void study() {
        System.out.println(name + "正在学习。");
    }

    public void takeExam() {
        System.out.println(name + "正在参加考试。");
    }

    public void displayInformation() {
        System.out.println("姓名：" + name);
        System.out.println("年龄：" + age);
        System.out.println("性别：" + gender);
        System.out.println("学号：" + studentId);
        System.out.println("GPA：" + gpa);
    }

    private String generateStudentId() {
        // 生成学生ID的逻辑
        return "S" + Math.abs(name.hashCode());
    }
}


// 第二个类：图书类
class Book {
    // 属性
    private String title;
    private String author;
    private int year;
    private String isbn;
    private boolean borrowed;

    // 构造方法
    public Book(String title, String author, int year) {
        this.title = title;
        this.author = author;
        this.year = year;
        this.isbn = generateISBN();
        this.borrowed = false;
    }

    public Book(String title, String author, int year, String isbn) {
        this.title = title;
        this.author = author;
        this.year = year;
        this.isbn = isbn;
        this.borrowed = false;
    }

    // 方法
    public void borrowBook() {
        if (!borrowed) {
            borrowed = true;
            System.out.println("成功借阅图书《" + title + "》。");
        } else {
            System.out.println("图书《" + title + "》已被借出。");
        }
    }

    public void returnBook() {
        if (borrowed) {
            borrowed = false;
            System.out.println("成功归还图书《" + title + "》。");
        } else {
            System.out.println("图书《" + title + "》未被借出。");
        }
    }

    public void displayInformation() {
        System.out.println("书名：" + title);
        System.out.println("作者：" + author);
        System.out.println("出版年份：" + year);
        System.out.println("ISBN：" + isbn);
        System.out.println("是否借出：" + (borrowed ? "是" : "否"));
    }

    private String generateISBN() {
        // 生成ISBN的逻辑
        return "ISBN-" + Math.abs(title.hashCode());
    }
}


public class Main {
    public static void main(String[] args) {
        // 创建两个 Student 对象
        Student student1 = new Student("张三", 18, "男");
        Student student2 = new Student("李四", 20, "女", 3.8);

        // 调用 Student 类的方法
        student1.study();
        student2.takeExam();
        student1.displayInformation();

        System.out.println();

        // 创建两个 Book 对象
        Book book1 = new Book("Java编程入门", "张三", 2022);
        Book book2 = new Book("Python数据分析", "李四", 2021, "978-1234567890");

        // 调用 Book 类的方法
        book1.borrowBook();
        book2.returnBook();
        book1.displayInformation();
    }
}
